{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "KNN PROGECT\n",
      "<GPLv3>\n",
      "正在导入信息……\n",
      "元素： Na 相对原子质量：22.9898\n",
      "元素： H  相对原子质量：1.0\n",
      "元素： He 相对原子质量：4.0\n",
      "元素： Li 相对原子质量：6.941\n",
      "元素： O  相对原子质量：15.9994\n",
      "元素： K  相对原子质量：39.0983\n",
      "元素： Al 相对原子质量：27.0\n",
      "元素： C  相对原子质量：12.011\n",
      "元素： Nb 相对原子质量：92.9064\n",
      "元素： Sb 相对原子质量：121.75\n",
      "元素： Bi 相对原子质量：208.9804\n",
      "元素： Zr 相对原子质量：91.224\n",
      "目标产物：NaO\n",
      "配置35.0g\n",
      "NaO\n",
      "+------+--------+-------+---------+\n",
      "| 元素 |  来源  |  纯度 | 质量(g) |\n",
      "+------+--------+-------+---------+\n",
      "|  Na  | Na2CO3 | 0.998 | 47.6676 |\n",
      "+------+--------+-------+---------+\n",
      "send the results to KNN?(y/n)n\n"
     ]
    }
   ],
   "source": [
    "#python3\n",
    "import re\n",
    "from prettytable import PrettyTable\n",
    "#import indog\n",
    "from indog import shi\n",
    "from cal1 import welldog,calone\n",
    "from sourse import sdogread\n",
    "from cal3 import calthree\n",
    "from post import knnpost\n",
    "zhiliang={}\n",
    "listdata=[]\n",
    "aimdog={}\n",
    "def start():\n",
    "    '''启动界面'''\n",
    "    print(\"KNN PROGECT\")\n",
    "    print('<GPLv3>')\n",
    "start()\n",
    "conf=''\n",
    "def readconf():\n",
    "    global conf\n",
    "    conf=['','']\n",
    "    '''读取配置文件'''\n",
    "    f = open ('data.conf','r')\n",
    "\n",
    "    #conf=0\n",
    "    #while True:\n",
    "\n",
    "    fline = f.readlines()\n",
    "    ###删除注释\n",
    "    for i in fline:\n",
    "        if i.startswith('#') or not re.match('.*=.*',fline[fline.index(i)]):\n",
    "            del fline[fline.index(i)]\n",
    "        else:\n",
    "            pass\n",
    "\n",
    "\n",
    "    conf=fline\n",
    "\n",
    "\n",
    "    #print(conf)\n",
    "    f.close()\n",
    "    return conf\n",
    "def hconf(confl):\n",
    "    '''对配置文件中的信息进行解读'''\n",
    "    #print(confl)\n",
    "    comdog=re.compile(r'(.*)=(.*)')\n",
    "    for j in confl:\n",
    "        jdog=comdog.findall(j)\n",
    "        zhiliang[jdog[0][0]]=float(jdog[0][1])\n",
    "    #print(zhiliang)\n",
    "    print('正在导入信息……')\n",
    "    for name , mass in zhiliang.items():\n",
    "        print(\"元素： \"+name.ljust(3)+'相对原子质量：'+str(mass))\n",
    "\n",
    "def indog():\n",
    "    aimdog=input('目标产物：')\n",
    "    return aimdog\n",
    "\n",
    "hconf(readconf())\n",
    "#print(zhiliang)\n",
    "#hconf(ll)\n",
    "#readconf()\n",
    "#hconf(readconf())\n",
    "#print(conf)\n",
    "#print(shi(indog()))\n",
    "dogin=indog()\n",
    "shidog=shi(dogin)#warn\n",
    "# print(shidog)\n",
    "# print(conf)\n",
    "# print(calone(conf,shidog))\n",
    "ans=calthree(sdogread(),shidog,conf)\n",
    "\n",
    "table = PrettyTable([\"元素\", \"来源\",\"纯度\",\"质量(g)\"])\n",
    "for ansdog in ans:\n",
    "    table.add_row([ansdog,ans[ansdog][0],ans[ansdog][3],(\"%.4f\" % ans[ansdog][1])])\n",
    "anslines=dogin+'\\n'+str(table)\n",
    "print(anslines)\n",
    "keydog=input(\"send the results to KNN?(y/n)\")\n",
    "if keydog=='y':\n",
    "    knnpost(anslines)\n",
    "else:\n",
    "    pass\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
